//
//  ViewController.swift
//  LYHelloComponent
//
//  Created by 1260197127@qq.com on 09/27/2021.
//  Copyright (c) 2021 1260197127@qq.com. All rights reserved.
//

import UIKit
import LYHelloComponent


class ViewController: UIViewController {

    public var imageUrl:String?
    fileprivate lazy var photoImageView:UIImageView={
       let imageView = UIImageView()
        return imageView
    }()
    let urls = [
                 "http://oe-images.haoqipei.com/image/9bc513c6782a7a181b42c2ee75d88261.png",
                 "http://ww3.sinaimg.cn/bmiddle/7ef8e115jw1f972pb91fng206o06odqk.gif",
                 "http://ww3.sinaimg.cn/bmiddle/7ef8e115jw1f972pb91fng206o06odqk.gif",
                 "http://oe-images.haoqipei.com/image/9bc513c6782a7a181b42c2ee75d88261.png",
                 "http://ww3.sinaimg.cn/bmiddle/7ef8e115jw1f972pb91fng206o06odqk.gif",
                 "http://ww2.sinaimg.cn/bmiddle/7ef8e115jw1f972pdnt0tg206o06odq8.gif",
                 "http://ww1.sinaimg.cn/bmiddle/7ef8e115jw1f95qjargkzg20740740u8.gif",]
    @IBAction func BtnClick(_ sender: Any) {
      
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let width = (self.view.bounds.size.width - 15*4)/3.0;
        for i in 0..<self.urls.count {
            let imageView = UIImageView(frame: CGRect(x: 15+(width+15)*CGFloat((i%3)), y: 64+(width+15)*CGFloat((i/3)), width: width, height: width))
//            imageView.clipsToBounds = true
            imageView.backgroundColor = .red
//            imageView.contentMode = .scaleAspectFill
            let tap = UITapGestureRecognizer(target: self, action: #selector(imageTapClicked(tap:)))
            imageView.isUserInteractionEnabled = true
            imageView.tag = i+1
            imageView.addGestureRecognizer(tap)
            imageView.sd_setImage(with: URL(string: self.urls[i])) { image, _, _, _ in
                
            }
            view.addSubview(imageView)
        }

    }
    @objc func imageTapClicked(tap:UITapGestureRecognizer){
        var imageViewArray:[UIImageView] = [UIImageView]()
        let startIndex = (tap.view?.tag ?? 0) - 1
        for index in 0..<urls.count {
            let imageView:UIImageView = view.viewWithTag(index+1) as? UIImageView ?? UIImageView()
            imageViewArray.append(imageView)
        }
    
        
        
        PhotoPreviewVC.showPhotoView(self, imageUrlArray: urls, imageViewArray: imageViewArray, image: nil, startIndex: startIndex)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

